﻿function AzureOnlineBlobsView(context) {

    var self = this;

    var screen = ko.observable('');

    var blobContainersView = new AzureOnlineBlobsContainersListView(context);
    var blobsView = new AzureOnlineBlobsListView(context);
    var leaseDetails = new AzureOnlineManageLeaseViewModel(context);
    var blobDetails = new AzureOnlineBlobDetailsView(context);
    var containerDetails = new AzureOnlineBlobContainerDetailsView(context);
    var deleteBlobDetails = new AzureOnlineBlobDeleteView(context);
    var deleteContainerDetails = new AzureOnlineBlobContainerDeleteView(context);
    var pageBlobViewer = new AzureOnlinePageBlobViewer(context);

    var spaRuntime = context.spaRuntime;

    var containersRoute = spaRuntime.findRouteByName('blobs').addExecute(function (ev, args, phash) {
        screen('containers');
    });

    var blobsRoute = spaRuntime.findRouteByName('blobContainerDetails').addExecute(function (ev, args, phash) {
        screen('blobs');
    });

    var pageBlobViewerRoute = spaRuntime.findRouteByName('pageBlobViewer').addExecute(function (ev, args, phash) {
        screen('pageBlobViewer');
    });

    context.api.subscribe(function () {
        if (spaRuntime.getCurrentRoute() == blobsRoute) {
            containersRoute.navigateHash({});
        }
        if (spaRuntime.getCurrentRoute() == pageBlobViewerRoute) {
            containersRoute.navigateHash({});
        }
    });
    
    self.blobContainersView = blobContainersView;
    self.blobsView = blobsView;
    self.deleteContainerDetails = deleteContainerDetails;
    self.leaseDetails = leaseDetails;
    self.blobDetails = blobDetails;
    self.containerDetails = containerDetails;
    self.deleteBlobDetails = deleteBlobDetails;
    self.pageBlobViewer = pageBlobViewer;
    self.screen = screen;
    self.context = context;
}